<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use App\Http\Model\AudioApi;


class MoonInviteUser extends Base
{
    protected $table = 'moon_invite_user';

    public function __construct(array $attributes = [])
    {
        parent::__construct($this->table, $attributes);
    }


    public function create($new_uid, $user_id)
    {
        $data['user_id'] = $new_uid;
        $data['invite_uid'] = $user_id;
        $data['status'] = 0;
        return DB::table($this->table)->insert($data);
    }

    public function getUser($user_id, $invite_uid)
    {
        $where['user_id'] = $user_id;
        $where['invite_uid'] = $invite_uid;
        $where['status'] = 0;
        $res = DB::table($this->table)->where($where)->first();
        if (!$res) {
            return false;
        }
        return $res;

    }

    public function getInviteUser($user_id)
    {
        $where['user_id'] = $user_id;
        $where['status'] = 0;
        $res = DB::table($this->table)->where($where)->first();
        if (!$res) {
            return false;
        }
        return $res;

    }


    public function updateStatus($user_id)
    {
        //充值
        $where['user_id'] = $user_id;
        $data['status'] = 1;
        return DB::table($this->table)->where($where)->update($data);
    }

}